//
//  MapView.swift
//  ChinaLandMark
//
//  Created by Felix Hi on 2021/6/28.
//  UIKit中的View转换成swiftUI中的View
//

import SwiftUI
import MapKit

struct MapView: UIViewRepresentable {
    let center: CLLocationCoordinate2D
    
    func makeUIView(context: Context) -> MKMapView { MKMapView() }
    
    func updateUIView(_ uiView: MKMapView, context: Context) {
        // 设置地图中心点, 和显示范围
        // let center = CLLocationCoordinate2D(
        //     latitude: 39.9087243,
        //     longitude: 116.3952859
        // )
        
        let span = MKCoordinateSpan(
            latitudeDelta: 0.02,
            longitudeDelta: 0.02
        )
        
        uiView.setRegion(
            MKCoordinateRegion(
                center: center,
                span: span
            ),
            animated: true
        )
    }
}

struct MapView_Previews: PreviewProvider {
    static var previews: some View {
        MapView(center: CLLocationCoordinate2D(
            latitude: 39.9087243,
            longitude: 116.3952859
        ))
    }
}
